﻿using System;
using System.Collections.Generic;
using System.Text;
using Sinacor.Infra.Core.ProcessManager.Server;
using PSE.ProcessManager.Common.Gateway;
using PSE.ProcessManager.Server.InteligenceModules;
using Sinacor.Infra.Common.Exceptions;
using Sinacor.Infra.Service.ExceptionHandling;

namespace Sinacor.Process.Bovespa.MensagensAlocacao.Server.ProcessImplementation
{
    public class MensagensAlocacao : SinacorBaseProcessServer<ProcessLogic.MensagensAlocacao>, ISimpleExecutionProcess
    {
        #region Campos

        private const int PROCESSID = ProcessEntity.Catalog.MensagensAlocacao.ProcessID;
        private const string NAME = "MensagensAlocacao";

        #endregion
        #region Construtor

        public MensagensAlocacao()
        {
            this.Id = PROCESSID;
            this.Name = NAME;
        }

        #endregion

        #region Métodos

        /// <summary>
        /// Executa o processo de transmissão de alocações
        /// </summary>
        /// <param name="message"></param>
        public void Execute(BaseMessage message)
        {
            try
            {
                //while (!System.Diagnostics.Debugger.IsAttached)
                //    System.Threading.Thread.Sleep(2500);

                ProcessEntity.DadosExecucao dadosExecucao = message.RetrieveParameter<ProcessEntity.DadosExecucao>();
                this.ProcessLogic.Inicializar();
                this.ProcessLogic.Execute(dadosExecucao);
            }
            catch(Exception ex)
            {
                this.HandleException(ex);
            }
            finally
            {
                this.Finalize();
            }
        }
        #endregion
    }
}